<?php
	require_once (dirname(__FILE__)."/../../config/Config.inc");
	require_once (dirname(__FILE__)."/../../config/api.inc");
	require_once ("load.php");
	
	$parm = requestArrayParm($_REQUEST);
	
	$result['status'] = '1';
	
	unset($wheres, $pages, $sorts,$list);
	
	$wheres['userid'] = $userinfo['id'];
	
	$wheres['status'] = $parm['status'];
	$sorts['tztime'] = 'desc';
	if($parm['status'] == '3')
	{
		$pages['page'] = 1;
		$pages['rows'] = 20;
		$resData = _SqlTool::getList('tzinfo', $wheres, $pages, $sorts);
		foreach ($resData['list'] as $key => $v)
		{
			unset($info,$query);
			$query['id'] = $v['pt_id'];
			$pingtai = _SqlTool::getInfo('pingtai', $query);
			
			unset($info,$query);
			$query['id'] = $v['cp_id'];
			$chanpin = _SqlTool::getInfo('chanpin', $query);
			
			unset($temp);
			$temp['logo'] = "https://resource.jinfumeng.com/".$pingtai['pt_logo'];
			$temp['name'] = $chanpin['cp_mc'];
			$temp['tags'] = $CP_FS[$chanpin['cp_style']];
			$temp['yearRate'] = $chanpin['cp_yqnh'];
			$temp['money'] = $chanpin['cp_qtje'];
			if($chanpin['cp_type'] == '1')
			{
				$gdfa = json_decode($chanpin['cp_gdfa'],true);
				$max = 0;
				foreach ($gdfa as $k => $v)
				{
					if(intval($v['tzje']) > $max)
					{
						$max = intval($v['tzje']);
						$temp['reBack'] = intval($v['lx'])+intval($v['fl'])+intval($v['hb']).'元';
					}
				}
			}
			if($chanpin['cp_type'] == '2')
			{
				$temp['reBack'] = $chanpin['cp_yqnh'];
			}
			$temp['time'] = $chanpin['cp_tzqx'];
			$temp['qixianlx'] = $chanpin['cp_tzqxlx'];
			$temp['tzdata'] = date('Y-m-d',$v['tztime']);
			
			$list[] = $temp;
		}
	}
	else
	{
		$resData = _SqlTool::getList('tzinfo', $wheres, $pages, $sorts);
		foreach ($resData as $key => $v)
		{
			unset($info,$query);
			$query['id'] = $v['pt_id'];
			$pingtai = _SqlTool::getInfo('pingtai', $query);
			
			unset($info,$query);
			$query['id'] = $v['cp_id'];
			$chanpin = _SqlTool::getInfo('chanpin', $query);
			
			unset($temp);
			$temp['logo'] = "https://resource.jinfumeng.com/".$pingtai['pt_logo'];
			$temp['name'] = $chanpin['cp_mc'];
			$temp['tags'] = $CP_FS[$chanpin['cp_style']];
			$temp['yearRate'] = $chanpin['cp_yqnh'];
			$temp['money'] = $chanpin['cp_qtje'];
			if($chanpin['cp_type'] == '1')
			{
				unset($query);
				$query['cp_id'] = $chanpin['id'];
				$temp['reBack'] = _SqlTool::getMax('cp_gdfa', $query, $between, 'fanli');
			}
			if($chanpin['cp_type'] == '2')
			{
				$temp['reBack'] = $chanpin['cp_fl'];
			}
			$temp['time'] = $chanpin['cp_tzqx'];
			$temp['qixianlx'] = $chanpin['cp_tzqxlx'];
			$temp['tzdata'] = date('Y-m-d',$v['tztime']);
			$temp['fldata'] = date('Y-m-d',$v['fltime']);
			$temp['flmoney'] = $v['fanli'];
			$temp['type'] = $chanpin['cp_type'];
			$list[] = $temp;
		}
	}
	
	$result['list'] = $list;
	
	echoJSON($result);
	
	
	
	
	